// 注册按钮的点击事件；
$('#goto-register').on('click', () => {
    $('#register').stop().show()
});
//登录按钮的点击事件；
$('#goto-login').on('click', () => {
    $('#register').stop().hide()
})
////表单提交；注册功能
$('#register .layui-form').on('submit', function (e) {
    e.preventDefault()
    let data = {
        username: $('#register input[name=username]').val(),
        password: md5($('#register input[name=password]').val())
    }
    let arr = []
    for (var key in data) {
        arr.push(`${key}=${data[key]}`)
    }
    let argstr = arr.join('&')
    console.log(argstr);
    registerApi(argstr, (re) => console.log(re))
})


//登录功能
$('#login .layui-form').on('submit', function (e) {
    e.preventDefault();
    let data = {
        username: $('#login input[name=username]').val(),
        password: md5($('#login input[name=password]').val())
    }
    let arr = [];
    for (let key in data) {
        arr.push(`${key}=${data[key]}`)
    }
    let argStr = arr.join('&');

    loginApi(argStr, (re) => {
        sessionStorage.setItem('token', re.data.token);
        window.location.href = './index.html'

    })
})
